// pages/doctor-my-customer/doctor-my-customer.js
var app = getApp()
Page({
  data: {
    imgUrl: app.globalData.imgUrl,          // 线上图片
    localImg: app.globalData.staticimgUrl,  // 本地图片
    cur: 1,
    listData:[],
    pagenum: 1,                             // 页数
    pagesize: 10                            // 每页数量
  },
  onLoad: function (options) {
    this.getDealList(); 
  },
  // 切换
  tabCurrent(e) {
    const cur = e.target.dataset.index;
    1 == cur && this.getDealList();
    2 == cur && this.getCustomersList();
    this.setData({
      cur
    })
  },
  // 加载更多
  moreInfo() {
    let pagenum = this.data.pagenum + 1;
    this.setData({
      pagenum
    });
    1 == cur && this.getDealList();
    2 == cur && this.getCustomersList();
  },
  // 已成交
  getDealList: function () {
    const that = this;
    const doctorId = wx.getStorageSync('userid');
    const param = {
      pagenum: this.data.pagenum,
      pagesize: this.data.pagesize,
      loginUserId :doctorId
    }
    app.request({
      url: 'shopp/orderApi/getMyCustomerByComplete',
      data: param,
      success(res) {
        let listData = res.data;
        if (param.pagenum != 1) {
          listData = that.data.listData.concat(listData);
        }
        that.setData({
          listData
        })
      }
    })
  },
  // 预约客户
  getCustomersList: function () {
    const that = this;
    const doctorId = wx.getStorageSync('userid');
    const param = {
      pagenum: this.data.pagenum,
      pagesize: this.data.pagesize,
      loginUserId: doctorId
    }
    app.request({
      url: 'shopp/orderApi/getMyCustomerByBespeak',
      data: param,
      success(res) {
        let listData = res.data;
        if (param.pagenum != 1) {
          listData = that.data.listData.concat(listData);
        }
        that.setData({
          listData
        })
      }
    })
  },
  // 用户详情
  entryDetail(e){
    const customerid = e.currentTarget.dataset.customerid;
    wx.navigateTo({
      url: '/pages/doctor-user-detail/doctor-user-detail?customerid=' + customerid
    });
  }

})